package ld.oauth.blog.controller.user;


import com.ld.anotation.Log;
import com.ld.common.ResultInfoFactory;
import ld.oauth.blog.model.bo.CheckOldPasswordBo;
import ld.oauth.blog.model.bo.SysUserBo;
import ld.oauth.blog.model.po.user.SysUser;
import ld.oauth.blog.model.qo.UserArticleQo;
import ld.oauth.blog.model.vo.UserArticleVo;
import ld.oauth.blog.model.vo.UserQuestionVo;
import ld.oauth.blog.service.user.SysUserService;
import ld.oauth.blog.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author
 * @since 2022-08-29
 */
@RestController
@RequestMapping("/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 根据id获取用户信息
     *
     * @return
     */
    @RequestMapping("/getUserInfo/{userId}")
    @Log(module = "用户模块",description = "根据id获取用户信息")
    public ResultInfoFactory<SysUser> getUserInfo(@PathVariable("userId") Integer userId) {
        SysUser sysUser = sysUserService.getBaseMapper().selectById(userId);
        return ResultInfoFactory.success(sysUser);
    }

    /**
     * 修改用户信息
     *
     * @param sysUserBo
     * @return
     */
    @PostMapping("/saveOrUpdateUser")
    @Log(module = "用户模块",description = "修改用户信息")
    public ResultInfoFactory saveOrUpdateUserBo(@RequestBody SysUserBo sysUserBo) {
        return sysUserService.saveOrUpdateUserBo(sysUserBo) == true ? ResultInfoFactory.success() : ResultInfoFactory.failed();
    }

    /**
     * 分页条件查询用户的文章信息
     *
     * @param userArticleQo
     * @return
     */
    @PostMapping("/articlePageQuery")
    @Log(module = "用户模块",description = "分页条件查询用户的文章信息")
    public ResultInfoFactory<PageResult<UserArticleVo>> articlePageQuery(@RequestBody UserArticleQo userArticleQo) {
        return ResultInfoFactory.success(sysUserService.articlePageQuery(userArticleQo));
    }

    /**
     * 分页条件查询用户的问题信息
     *
     * @param userArticleQo
     * @return
     */
    @PostMapping("/questionPageQuery")
    @Log(module = "用户模块",description = "分页条件查询用户的问题信息")
    public ResultInfoFactory<PageResult<UserQuestionVo>> pageQuery(@RequestBody UserArticleQo userArticleQo) {
        return ResultInfoFactory.success(sysUserService.questionPageQuery(userArticleQo));
    }

    /**
     * 校验旧密码是否正确
     *
     * @param checkOldPasswordBo
     * @return
     */
    @PostMapping("/check/password")
    @Log(module = "用户模块",description = "校验旧密码是否正确")
    public ResultInfoFactory checkOldPassword(@RequestBody CheckOldPasswordBo checkOldPasswordBo) {
        return sysUserService.checkOldPassword(checkOldPasswordBo);
    }

    /**
     * 修改密码
     * @param checkOldPasswordBo
     * @return
     */
    @PostMapping("/updatePassword")
    @Log(module = "用户模块",description = "修改密码")
    public ResultInfoFactory updatePassword(@RequestBody CheckOldPasswordBo checkOldPasswordBo) {
        return sysUserService.updatePassword(checkOldPasswordBo);
    }



}
